﻿using Collection.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WanPiJie;

namespace Collection.Export.Services.Wanpijie
{
    public class AttributeValueService : Service<PropertyValue>
    {
        public override PropertyValue Import(PropertyValue propertyValue)
        {
            var pav = propertyValue.ToProductAttributeValue();
            if (WpjSf.CategoryService.HasProductAttrVal(pav.CatalogId, pav.AttributeId, pav.ThirdId))
            {
                WpjSf.CategoryService.UpdateProductAttrVal(pav.CatalogId, pav.AttributeId, pav.ThirdId, pav.Value);
                this.OnUpdate(propertyValue);
            }
            else
            {
                WpjSf.CategoryService.AddProductAttrVal(pav.CatalogId, pav.AttributeId, pav.ThirdId, pav.Value);
                this.OnInsert(propertyValue);
            }
            return propertyValue;
        }
    }
}
